package com.lam.system.service.impl;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.StringUtils;
import com.lam.framework.bean.entity.SysOperLog;
import com.lam.system.mapper.SysOperLogMapper;
import com.lam.system.param.SysOperLogParam;
import com.lam.system.service.SysOperLogService;

/**
 * 操作日志记录Service业务层处理
 * 
 * @author admin
 * @date 2022-08-03
 */
@Service
public class SysOperLogServiceImpl implements SysOperLogService {


    @Autowired
    private SysOperLogMapper sysOperLogMapper;
    
    /**
     * 查询操作日志记录
     * 
     * @param id ID
     * @return 单个对象
     */
    @Override
    @Transactional(readOnly = true)
    public SysOperLog selectById(String id) {

        return sysOperLogMapper.selectById(id);
    }

    /**
     * 查询操作日志记录列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<SysOperLog> selectList(SysOperLogParam param) {
    
        QueryWrapper<SysOperLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(param.getTitleKey()), "title", param.getTitleKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getTitle()), "title", param.getTitle());
        queryWrapper.like(StringUtils.isNotBlank(param.getOperKey()), "oper", param.getOperKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getOper()), "oper", param.getOper());
        queryWrapper.eq(StringUtils.isNotBlank(param.getBusinessType()), "business_type", param.getBusinessType());
        queryWrapper.eq(StringUtils.isNotBlank(param.getOperatorType()), "operator_type", param.getOperatorType());
        queryWrapper.like(StringUtils.isNotBlank(param.getReqUrlKey()), "req_url", param.getReqUrlKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getReqUrl()), "req_url", param.getReqUrl());
        queryWrapper.like(StringUtils.isNotBlank(param.getReqParamKey()), "req_param", param.getReqParamKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getReqParam()), "req_param", param.getReqParam());
        queryWrapper.eq(StringUtils.isNotBlank(param.getReqIp()), "req_ip", param.getReqIp());
        queryWrapper.eq(StringUtils.isNotBlank(param.getReqStatus()), "req_status", param.getReqStatus());

        queryWrapper.ge(Objects.nonNull(param.getElTimeBegin()), "el_time", param.getElTimeBegin());
        queryWrapper.le(Objects.nonNull(param.getElTimeEnd()), "el_time", param.getElTimeEnd());
        

        queryWrapper.le(Objects.nonNull(param.getOperTimeBegin()), "oper_time", param.getOperTimeBegin());
        queryWrapper.ge(Objects.nonNull(param.getOperTimeEnd()), "oper_time", param.getOperTimeEnd());
        
        queryWrapper.like(StringUtils.isNotBlank(param.getOperNameKey()), "oper_name", param.getOperNameKey());
        queryWrapper.eq(StringUtils.isNotBlank(param.getOperName()), "oper_name", param.getOperName());

        return sysOperLogMapper.selectList(queryWrapper);
    }

    /**
     * 新增操作日志记录
     * 
     * @param sysOperLog 
     * @return 
     */
    @Override
    @Transactional
    public int insert(SysOperLog sysOperLog) {
    
        return sysOperLogMapper.insert(sysOperLog);
    }

    /**
     * 修改操作日志记录
     * 
     * @param sysOperLog 
     * @return 
     */
    @Override
    @Transactional
    public int update(SysOperLog sysOperLog) {
    
        return sysOperLogMapper.updateById(sysOperLog);
    }

    /**
     * 删除操作日志记录信息
     * 
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(String idStr) {
    	
    	if(StringUtils.isBlank(idStr)) {
            return 0;
    	}
        return sysOperLogMapper.deleteBatchIds(StringUtils.str2List(idStr));
    }

}
